﻿@using XCode;
@using XCode.Configuration;
@{
    var pair = Model as Pair;
    var entity = pair.First as IEntity;
    var item = pair.Second as FieldItem;

    var value = entity[item.Name];
}
@if (item.IsIdentity)
{
    <td class="text-center">@value</td>
}
else
{
    switch (Type.GetTypeCode(item.Type))
    {
        case TypeCode.Boolean:
            if ((Boolean)value)
            {
                <td class="text-center">
                    <i class="glyphicon glyphicon-ok" style="color: green;"></i>
                </td>
            }
            else
            {
                <td class="text-center">
                    <i class="glyphicon glyphicon-remove" style="color: red;"></i>
                </td>
            }
            break;
        case TypeCode.DateTime:
            var dt = (DateTime)value;
            <td>@dt.ToFullString("")</td>
            break;
        case TypeCode.Decimal:
            <td>@value</td>
            break;
        case TypeCode.Single:
        case TypeCode.Double:
            <td>@value</td>
            break;
        case TypeCode.Byte:
        case TypeCode.Int16:
        case TypeCode.Int32:
        case TypeCode.Int64:
        case TypeCode.UInt16:
        case TypeCode.UInt32:
        case TypeCode.UInt64:
            //特殊处理枚举
            if (item.Type.IsEnum)
            {
                var val = "";
                try
                {
                    val = System.EnumHelper.GetDescription((Enum)value) ?? value + "";
                }
                catch { }
                <td class="text-center">@val</td>
            }
            else if (item.Name.EqualIgnoreCase("CreateUserID", "UpdateUserID"))
            {
                var provider = ViewData["Provider"] as IManageProvider;
                <td>@provider.FindByID(value)</td>
            }
            else
            {
                <td class="text-right">@Convert.ToInt64(value).ToString("n0")</td>
            }
            break;
        case TypeCode.String:
        default:
            {
                var val = value;
                var map = item.Map;
                if (map != null && map.Provider != null && val + "" != "")
                {
                    var dic = new RouteValueDictionary();
                    var key = map.Provider.Key;
                    if (!key.IsNullOrEmpty() && item.OriField != null) { dic[key] = entity[item.OriField.Name]; }
                    <td>@Html.ActionLink(value + "", "Edit", map.Provider.EntityType.Name, dic, null)</td>
                }
                else if (item.Name.EqualIgnoreCase("CreateIP", "UpdateIP"))
                {
                    <td title="@((value+"").IPToAddress())">@value</td>
                }
                else if (item.Name.EqualIgnoreCase("Remark", "Description"))
                {
                    //防止内容过长
                    <td style="max-width:600px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" title="@value">@value</td>
                }
                else
                {
                    <td>@value</td>
                }
            }
            break;
            @*default:
                <td>@value</td>
                break;*@
    }
}